//app 里面的一些信息
const musicInfo = {
  state:{
    bottomMenuInfo:{
      show:false,
      type:'sheet',
      title:'',
      id:'',
      btnList:{
        sheet: [
          {
            name:'分享',
            icon:'icon-share'
          },
          {
            name:'编辑',
            icon:'icon-edit'
          },
          {
            name:'删除',
            icon:'icon-delete'
          }
         ],
        music:[
          {
            name:'分享',
            icon:'icon-share'
          },
          {
            name:'删除',
            icon:'icon-delete'
          }
        ]
      }
    },
    playingSheetInfo:{
      show:false,
      count:0,
      list:{}
    }
  },
  getters:{
    getBottomMenuShow: state => state.bottomMenuInfo.show,
    getBottomMenuInfo: state => state.bottomMenuInfo,
    getBottomMenuTitle: state => state.bottomMenuInfo.title,
    getBobbomMenuBtnInfo: state => state.bottomMenuInfo.btnList[state.bottomMenuInfo.type],
    getPlayingInfo: state => state.playingSheetInfo,
  },
  mutations:{
    setBottomMenuShow(state,bool){
      state.bottomMenuInfo.show = bool;
    },
    setBottomMenuType(state,str){
      state.bottomMenuInfo.type = str;
    },
    setBottomMenuId(state,id){
      state.bottomMenuInfo.id = id;
    },
    setBottomMenuTitle(state,title){
      state.bottomMenuInfo.title = title;
    },
    setPlayingShow(state,bool){
      state.playingSheetInfo.show = bool;
    },
    //将歌曲信息添加到List
    addMusic2List(state,obj){
      let list = state.playingSheetInfo.list,
          id = obj.id;
      for(let k in list)
        if(!id || list[k].id == id)
          return ;

      //count 为列表的索引
      id = ++ state.playingSheetInfo.count ;
      list[id] = obj;
    },
    setPlayingList(state,obj){
      state.playingSheetInfo.list = obj;
    }
  },
  actions:{
    set_bottomMenuShow({commit},bool){
      commit('setBottomMenuShow',bool)
    },
    set_bottomMenuType({commit},str){
      commit('setBottomMenuType',str);
    },
    set_bottomMenuId({commit},id){
      commit('setBottomMenuId',id)
    },
    set_bottomMenuTitle({commit},title){
      commit('setBottomMenuTitle',title)
    },
    set_bottomMenuId({commit},id){
      commit('setBottomMenuId',id);
    },
    set_playingShow({commit},bool){
      commit('setPlayingShow',bool);
    },
    add_music2List({commit},obj){
      commit('addMusic2List',obj);
    },
    add_sheet2List({commit,rootState}){
      let info = rootState.sheetInfo.curSheet.info;
      console.log(info);
      for(let i=0;i<info.length;i++)
        commit('addMusic2List',info[i]);
    },
    set_playingList({commit},obj){
      commit('setPlayingList',obj);
    }
  }
}

export default musicInfo;